package com.work.vo.main;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.ser.std.ToStringSerializer;
import com.work.constant.DictBizConstant;
import com.work.utils.BigDecimalSerializer;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springblade.core.tool.utils.DateUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.system.cache.DictBizCache;
import org.springframework.format.annotation.DateTimeFormat;

import java.math.BigDecimal;
import java.time.LocalDate;

/**
 * 退关设置VO
 *
 * @author ：dujianyu
 * @since ：Created in 2024/5/27 15:28
 */
@Data
public class RetreatSetVO {

    /** 货运船ID */
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(name = "主键ID",notes = "")
    private Long id ;

    /** 货运船ID */
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(name = "货运船ID",notes = "")
    private Long transportShipId ;

    /** 货运舱单ID */
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(name = "货运舱单ID",notes = "")
    private Long transportBillId ;

    /** 理货舱单ID */
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(name = "理货舱单ID",notes = "")
    private Long tShipBillId ;

    @ApiModelProperty(value = "船名")
    private String shipNameZh;

    @ApiModelProperty(value = "货名")
    private String cargoType;

    @ApiModelProperty(value = "货名")
    private String cargoTypeName;

    @ApiModelProperty(value = "航次")
    private String voyage;

    @ApiModelProperty(value = "进出口")
    private String iE;

    @ApiModelProperty(value = "舱单号")
    private String billNo;

    /** 理货日期 */
    @DateTimeFormat(pattern = DateUtil.PATTERN_DATE)
    @JsonFormat(pattern = DateUtil.PATTERN_DATE)
    @ApiModelProperty(name = "理货日期",notes = "")
    private LocalDate tallyDate ;

    /** 时间段（班组） */
    @ApiModelProperty(name = "时间段（班组）",notes = "")
    private String timeSpace ;

    /** 时间段（班次） */
    @ApiModelProperty(name = "时间段（班次）",notes = "")
    private String timeSpaceName ;

    public String getTimeSpaceName() {
        if (Func.isNull(timeSpace)) {
            return "";
        }
        return DictBizCache.getValue("time_space", timeSpace);
    }

    /** 退关的场存垛位id */
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(name = "退关的场存垛位id",notes = "")
    private Long retreatStorageId ;

    /** 退关件数 */
    @ApiModelProperty(name = "退关件数",notes = "")
    private Integer retreatPiece ;

    /** 退关吨数 */
    @JsonSerialize(using = BigDecimalSerializer.class)
    @ApiModelProperty(name = "退关吨数",notes = "")
    private BigDecimal retreatTon ;

    /** 退关类型 */
    @ApiModelProperty(name = "退关类型",notes = "")
    private String retreatType ;

    /** 时间段（班次） */
    @ApiModelProperty(name = "时间段（班次）",notes = "")
    private String retreatTypeName ;

    public String getRetreatTypeName() {
        if (Func.isNull(retreatType)) {
            return "";
        }
        return DictBizCache.getValue(DictBizConstant.RETREAT_TYPE, retreatType);
    }

    /** 退关原因 */
    @ApiModelProperty(name = "退关原因",notes = "")
    private String retreatReason ;

    /** 区域ID */
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(name = "区域ID",notes = "")
    private Long storageAreaId ;

    /** 区域 */
    @ApiModelProperty(name = "区域",notes = "")
    private String storageAreaName ;

    /** 货场 */
    @JsonSerialize(using = ToStringSerializer.class)
    @ApiModelProperty(name = "货场",notes = "")
    private Long storagePositionId ;

    /** 货场 */
    @ApiModelProperty(name = "货场",notes = "")
    private String storagePositionName ;

    /** 货位 */
    @ApiModelProperty(name = "货位",notes = "")
    private String storageSpot ;

    /** 包装 */
    @ApiModelProperty(name = "包装",notes = "")
    private String storagePackageType ;

    /** 包装 */
    @ApiModelProperty(name = "包装",notes = "")
    private String storagePackageTypeName ;

    /** 库存件数 */
    @ApiModelProperty(name = "库存件数",notes = "")
    private Integer storagePiece ;

    /** 库存吨数 */
    @JsonSerialize(using = BigDecimalSerializer.class)
    @ApiModelProperty(name = "库存吨数",notes = "")
    private BigDecimal storageTon ;

    /** 库存件数 */
    @ApiModelProperty(name = "库存件数",notes = "")
    private Integer outPiece ;

    /** 库存吨数 */
    @JsonSerialize(using = BigDecimalSerializer.class)
    @ApiModelProperty(name = "库存吨数",notes = "")
    private BigDecimal outTon ;

    /** 库存件数 */
    @ApiModelProperty(name = "库存件数",notes = "")
    private Integer leftPiece ;

    public Integer getLeftPiece() {
        return retreatPiece - outPiece;
    }

    /** 库存吨数 */
    @JsonSerialize(using = BigDecimalSerializer.class)
    @ApiModelProperty(name = "库存吨数",notes = "")
    private BigDecimal leftTon ;

    public BigDecimal getLeftTon() {
        return retreatTon.subtract(outTon);
    }
}
